﻿using System;
using System.Windows;
using compshop.Infrastructure.CompShopDataService;

namespace compshop.Modules.DepartmentList.View
{
    /// <summary>
    /// Логика взаимодействия для PositionDialog.xaml
    /// </summary>
    public partial class DepartmentDialog : Window
    {
        public DepartmentDialog()
        {
            InitializeComponent();
        }

        public DepartmentDialog(Department department) 
            : this()
        {
            Department = department;
            DataContext = this;
        }

        public Department Department { set; get; }

        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            if (tbName.Text != String.Empty)
            {
                if (Department == null)
                    Department = new Department();
                Department.Name = tbName.Text;
                Department.Phone =tbPhone.Text;
                Department.Fax = tbFax.Text;
                Department.Address = tbAddress.Text;
                DialogResult = true;
                Close(); 
            }
            else MessageBox.Show(Resource.msgNameCannotBeEmpty);         
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
            Close();
        }
    }
}
